<?php
/**
 * Created by PhpStorm.
 * User: 17208
 * Date: 2020/10/14
 * Time: 11:21
 */

namespace extend;


class ScRedis
{
    /** @var  \Redis */
    private static $_redis;
    private static function init()
    {
        self::$_redis = new \Redis();
        $config = Config::get('redis');
        $conn = self::$_redis->connect($config['host'], $config['port']);
        if(!$conn) throw new \Exception("redis：连接失败！");

        $auth = self::$_redis->auth($config['password']); //设置密码
        if(!$auth) throw new \Exception("redis：密码错误！");
    }
    /** 获取redis实例 */
    public static function getInstance(){
        if(!self::$_redis){
            self::init();
        }
        return self::$_redis;
    }
}